<template>
  <div class="app-container">
    <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <el-menu-item index="1">公司级制度</el-menu-item>
      <el-menu-item index="2">部门级制度</el-menu-item>
    </el-menu>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="制度名称" prop="name">
        <el-input
          v-model="queryParams.regimeName"
          placeholder="请输入制度名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发布时间">
        <el-date-picker v-model="dateTime"
                        size="small"
                        style="width: 240px"
                        value-format="yyyy-MM-dd"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <div class="top-right-btn">
        <el-tooltip class="item" effect="dark" content="刷新" placement="top">
          <el-button size="mini" circle icon="el-icon-refresh" @click="handleQuery"/>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top">
          <el-button size="mini" circle icon="el-icon-search" @click="showSearch=!showSearch"/>
        </el-tooltip>
      </div>
    </el-row>

    <el-table v-loading="loading" :data="regimeList" border>
      <el-table-column label="序号" width="50px" align="center">
        <template slot-scope="scope">
          {{ scope.$index + (queryParams.current - 1) * queryParams.size+ 1 }}
        </template>
      </el-table-column>
      <el-table-column label="制度名称" align="center" prop="regimeName"/>
      <el-table-column label="类型" align="center" prop="typeName"/>
      <el-table-column label="适用部门" align="center" prop="deptName"/>
      <el-table-column label="创建时间" align="center" prop="createTime"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="text"
          icon="el-icon-search"
          @click="onSelect(scope.row)"
        >查看
        </el-button>
      </template>
    </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import {
    listRegime,
  } from "@/api/system/regime";

  export default {
    name: "regime",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 应用表格数据
        regimeList: [],
        dateTime:'',
        activeIndex: '1',
        fileUrl:'',

        // 查询参数
        queryParams: {
          current: 1,
          size: 10,
          regimeName: undefined,
          typeName: undefined,
          startTime: undefined,
          endTime: undefined,
          deptId:undefined
        },
        // 显示搜索条件
        showSearch: true,
        // 表单参数

      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询应用列表 */
      getList() {
       if(this.dateTime){
         this.queryParams.startTime=this.dateTime[0];
         this.queryParams.endTime=this.dateTime[1];
       }else{
         this.queryParams.startTime='2020-01-01';
         this.queryParams.endTime='2028-01-01';
       }
       if(this.activeIndex=="1"){
             this.queryParams.typeName='公司级';
       }else{
           this.queryParams.typeName='部门级';
       }

        this.loading = true;
        listRegime(this.queryParams).then(response => {

            this.regimeList=response.data;
            this.total = response.total;
            this.loading = false;
        })
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.current = 1;
        this.getList();
      },
      //切换公司级制度和部门级制度
      handleSelect(key, keyPath) {
        this.activeIndex=key;
         this.getList();
      },
      onSelect(data){
         window.open(data.regimeUrl);
      }


    }
  };
</script>
